<template>
  <div class="app-container">
    <h4 class="form-header h4">项目信息</h4>
    <el-descriptions border>
      <el-descriptions-item label="项目编号">{{ subform.subjectNo }}</el-descriptions-item>
      <el-descriptions-item label="项目名称">{{subform.subjectName}}</el-descriptions-item>
      <el-descriptions-item label="项目时间">{{ subform.ddate }}</el-descriptions-item>
      <el-descriptions-item label="立项时间">{{ subform.fireDate }}</el-descriptions-item>
      <el-descriptions-item label="项目状态">
        <el-tag size="small" type="success">{{subform.status}}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="完成时间">{{ subform.demandDate }}</el-descriptions-item>
      <el-descriptions-item label="描述">{{subform.desp}}</el-descriptions-item>
    </el-descriptions>

    <h4 class="form-header h4">项目处理</h4>
    <el-timeline>
      <el-timeline-item :timestamp="item.createTime" placement="top" v-for="(item,index) in processLogs" :key="index">
        <el-card>
          <el-row>
            <strong style="color: #57a8f5">{{item.createBy}}:</strong><span>{{item.desp}}</span>
          </el-row>
          <el-divider></el-divider>
          <el-row>
            <el-col :span="8">
              <el-tag size="small">开始时间：{{item.beginDate}}</el-tag>
            </el-col>
            <el-col :span="8">
              <el-tag size="small" type="success">进度:{{item.rate}}%</el-tag>
            </el-col>
            <el-col :span="8">
              <el-tag size="small">计划结束时间：{{item.pfinishDate}}</el-tag>
            </el-col>
          </el-row>
        </el-card>
      </el-timeline-item>

      <el-timeline-item :timestamp="parseTime()(new Date(), '{y}-{m}-{d}')" placement="top" >
        <el-card>
          <div slot="header" class="clearfix">
            <span>汇报处理进度-{{parseTime()(new Date(), '{y}-{m}-{d}')}}</span>
          </div>
          <el-form label-width="100px" ref="form" :model="form" :rules="rules" >
            <el-form-item label="描述" prop="desp">
              <el-input v-model="form.desp" type="textarea" placeholder="请输入内容" />
            </el-form-item>
            <el-row gutter="24">
              <el-col :span="8">
                <el-form-item label="开始时间" prop="beginDate">
                  <el-date-picker clearable
                                  v-model="form.beginDate"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="请选择开始时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="计划完成" prop="pfinishDate">
                  <el-date-picker clearable
                                  v-model="form.pfinishDate"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="请选择计划完成时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="进度百分比" prop="rate">
                  <el-input-number v-model="form.rate" min="0" max="100" placeholder="请输入项目进度百分比" label=""/>%
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item style="text-align: center;margin-left:-120px;margin-top:30px;">
              <el-button type="primary" @click="submitForm()">提交</el-button>
              <el-button @click="close()">返回</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-timeline-item>
    </el-timeline>



  </div>
</template>

<script>
import {  updateAuthRole } from "@/api/system/user";
import { getSubject } from '@/api/system/subject'
import { addProcess, findAllBySubjectId, listProcess, updateProcess } from '@/api/system/process'
import { parseTime } from '@/utils/ruoyi'

export default {
  name: "editSubject",
  data() {
    return {
       // 遮罩层
      loading: true,
      // 分页信息
      total: 0,
      pageNum: 1,
      pageSize: 10,
      // 选中角色编号
      roleIds:[],
      // 角色信息
      roles: [],
      processLogs:[],
      // 用户信息
      form: {},
      subform: {},
      rules: {
        desp: [
          { required: true, message: "描述不能为空", trigger: "blur" }
        ],
        beginDate: [
          { required: true, message: "开始时间时间不能为空", trigger: "blur" }
        ],
        pfinishDate: [
          { required: true, message: "计划完成时间不能为空", trigger: "blur" }
        ],
        rate: [
          { required: true, message: "进度百分比不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    const subjectId = this.$route.params && this.$route.params.id;
    if (subjectId) {
      this.loading = true;
      getSubject(subjectId).then((response) => {
        this.subform = response.data
        this.loading = false;
        this.getList(subjectId)
      });
    }
  },
  methods: {
    parseTime() {
      return parseTime
    },
    /** 单击选中行数据 */
    clickRow(row) {
      this.$refs.table.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.roleIds = selection.map((item) => item.roleId);
    },
    // 保存选中的数据编号
    getRowKey(row) {
      return row.roleId;
    },
    getList(subjectId) {
      this.loading = true;
      findAllBySubjectId(subjectId).then(response => {
        this.processLogs = response.data
        this.loading = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.subjectId = this.subform.subjectId
          this.form.subjectNo = this.subform.subjectNo
          this.form.category = this.subform.category
          addProcess(this.form).then(response => {
            this.$modal.msgSuccess("保存成功");
            this.getList(this.subform.subjectId);
          }).finally(() => {
          });
        }
      });
    },
    reset() {
      this.form = {
        beginDate: undefined,
        desp: undefined,
        pfinishDate: undefined,
        rate: undefined,
      };
      this.resetForm("form");
    },
    /** 关闭按钮 */
    close() {
      const obj = { path: "/system/user" };
      this.$tab.closeOpenPage(obj);
    },
  },
};
</script>
